<template>
	<view class="registcontent">
		<view class="navTitle">
		注册
		</view>
		<view class="content">
			<view class="phone">
				<input type="number" v-model="phone" placeholder="请输入手机号" maxlength="11" class="registinput"/>
				<view class="codeview" @click="yzm()">{{btnText}}</view>
			</view>
			<view class="code">
				<input type="number" maxlength="6" placeholder="请输入短信验证码" v-model="code" class="registinput"/>
			</view>
			<view class="passage">
				<input placeholder="请输入新密码(最少8位,数字+字母)" v-model="password" class="registinput" />
			</view>
			<view class="phone">
				<input type="number"  placeholder="请选择用户身份" :disabled="true" maxlength="11" class="registinput"/>
				<view class="codeview arrow" @click="chooseType()">
					<i class="iconfont" v-if="typeShow">&#xe63c;</i>
				    <i class="iconfont" v-else>&#xe632;</i>
				</view>
			</view>
			<view class="idType flx" v-show="typeShow">
				<view class="btnType" v-for="(item,index) in items" :class="{'active' :item.id == currentIndex}" @click="changeActive(item)">
					{{item.name}}
				</view>
       
			</view>
			<view class="server">
				<checkbox-group>
                    <label>
                        <checkbox value="name" checked="true"  @click="changeStu()" />
						
                    </label>
                    请阅读并同意
                    <text @click="open()">《云企商用户使用协议》</text>
                    及
                    <text>《云企商用户服务协议》</text>
                </checkbox-group>
			</view>
			
			<button type="default" class="regBtn" @click="reg()" v-bind:disabled="isdisabledFn">立即注册</button>
		</view>
	</view>
</template>

<script>
	import { ajax } from '../../api.js';
	export default {
		data() {
			return {
				baseUrl:'http://125.124.131.34:9090/CEB/',
				name:'我已阅读',
				phone:'',
				agree:true,
				item:[],
				count:1,
				sessionInfo:'',
				typeShow:false,
				btnDisabled:false,
				isdisabledFn:false,
				btnText:"获取验证码",
				code:'',
				password:'',
				smsbtn: {
					text: '获取验证码',
					status: false,
					codeTime: 60
			},
			items: [{
                    value: 'USA',
                    name: '代理商',
					id:5,
                },
                {
                    value: 'CHN',
                    name: '门店',
                    checked: 'true',
					id:6
                },
                {
                    value: 'BRA',
                    name: '生产加工',
					id:7
                },
                {
                    value: 'JPN',
                    name: '批发',
					id:8
                },
                {
                    value: 'ENG',
                    name: '运营商',
					id:9
                }
            ],
            currentIndex: 0,
			currentName:"",
			curType:'',
			timerId: null,
			};
		},
		onLoad() {
			
			
				var that = this;
				 uni.request({
				   url: '/CEB/login_getSessionId.action',
				    method: "get",
				    data: {
				       
				    },
				  success: (res) => {
				 	console.log(res.data);
					that.sessionInfo = res.data;
				 }
				});
				that.currentIndex = this.items[0].id;
			
		},
		methods: {
			
			open(){
				console.log("xieyi");
			},
				//跳转页面
			openinfo(url) {
			     
			     //var newsid = e.currentTarget.dataset.newsid ;    
			     uni.navigateTo({
			         url: url,
			         success: res => {},
			         fail: () => {},
			         complete: () => {}
			     });
			 },
			/* 选中复选框 */
			changeStu:function(){
				
				console.log('点击了复选框');
				var that = this;
				that.count = that.count +1;
				if(that.count %2 == 0){
					console.log("未选中");
					that.isdisabledFn = true;
				}else {
					console.log("选中了!!!");
					that.isdisabledFn = false;
				}
			
			},
			/* 获取验证码 */
			yzm:function(){
				console.log("1111");
				   var that=this;
                  if(!(/^1[345678]\d{9}$/.test(that.phone))){
                      uni.showToast({
                          msg: "手机号码格式不正确",
                          duration: 2000,
                          location: 'bottom'
                      });
                      return false;
                  } else{
                    // this.getMsg();
                     if (that.btnDisabled) {
                         return;
                     }else{
                       that.getSecond(60);
                       uni.request({
                          url: '/CEB/login_sendPhoneVerification.action',
                           method: "get",
						   
						  /* header: {
						      'Cookie': 'JSESSIONID='+ that.sessionInfo //自定义请求头信息
						   }, */
                           data: {
                               phoneNum:that.phone,
							  
                           },
						
						   success: (res) => {
						   	console.log(res.data);
						   }
                       })
					
					   
                     }
                  }
			},
			/* 显示隐藏发布类型 */
			chooseType:function(){
				console.log('点击了箭头');
				var that = this;
				that.typeShow = !that.typeShow;
			},
			
			 changeActive: function(item) {
			 	var that = this;
			 	that.currentIndex = item.id;
				that.currentName = item.name;
			 	console.log(that.currentIndex);
			    console.log(that.currentName);
			 },
			/* 注册 */
			reg:function(){
				console.log("可以点击");
				var that = this;
				 uni.request({
				   url:'/CEB/login_register.action',
				    method: "get",
				    data: {
				        phoneNum:that.phone,
						password:that.password,
						code:that.code,
						type:that.currentName
				    },
				  success: (res) => {
				 	console.log(res.data);
					if(res.data == 'success'){
						uni.navigateTo({
						    url: "../login/login",
						    success: res => {},
						    fail: () => {},
						    complete: () => {}
						});
					}else if(res.data == 'codeError'){
						uni.showToast({  
						title: "验证码错误!",  
						 duration: 2000 
					})  
					}else if(res.data == 'fail'){
						
							uni.showToast({  
							title: "注册失败!!",  
							 duration: 2000 
						})  
				 }
				 }
				})
			},
			/* 计时器 */
			    getSecond: function(wait) {
                    var _this = this;
                    var _wait = wait;
                    if (wait == 0) {
                        this.btnDisabled = false;
                        this.btnText = "获取验证码"
                        wait = _wait;
                    } else {
                        this.btnDisabled = true;
                        this.btnText = wait + "s"
                        wait--;
                        setTimeout(function() {
                                _this.getSecond(wait);
                            },
                            1000);
                    }
                }
		}
	}
</script>

<style>
	page {
		min-height: 100%;
		background-color: #F2F2F2;
		font-size: 32upx;
	}
	.navTitle{
		background: #FF542E;
		width: 100%;
		height: 100rpx;
		text-align: center;
		line-height: 100rpx;
		color: #fff;
		font-size: 38rpx;
	}
	.registcontent {
		width: 100%;
		background-color: #FFFFFF;
	}
	.content {
		width: 85%;
		margin: 0 auto;
		display: flex;
		flex-direction: column;
	}
	.registinput {
		width: 100%;
		border-bottom: 1upx solid #D4D4D4;
		padding-left: 8upx;
		height: 93upx;
		line-height: 93upx;
		margin-top: 29upx;
	}
	.flx{
		display: flex;
		justify-content: space-around;
	}
	.active{
		background: #FF542E!important;
	}
	.idType{
		margin-top: 30rpx;
	}
	.btnType{
		padding: 12rpx 22rpx;
		background: #C8C8C8;
		font-size: 28rpx;
		color: #fff;
		box-sizing: border-box;
		border-radius: 8rpx;
	}
	.phone{
		position: relative;
		}
	.codeview {
		position: absolute;
		right: 0;
		top: 24rpx;
		width: 165upx;
		line-height: 93upx;
		display: block;
		z-index: 999;
	}
	.server {
		font-size: 28rpx;
		color: #C8C8C8;
		margin-top: 50rpx;
		}
		.regBtn{
			color: #fff;
			width: 90%;
			height: 80rpx;
			line-height: 80rpx;
			font-size: 38rpx;
			margin: 0 auto;
			background: #FF542E;
			border-radius: 50rpx;
			margin-top: 100rpx;
			margin-bottom: 50rpx;
			}
			.arrow{
				width: 35rpx;
			}
</style>
